<?php
/**
 * Created by PhpStorm.
 * User: zlkmu
 * Date: 2017/9/28
 * Time: 12:53
 */
    require_once ('Object/MaJang/MajongCard.php');
    require_once ('Object/MaJang/MajongManager.php');
    require_once ('Object/MaJang/MajongRoom.php');
    require_once ('Object/MaJang/MajangPlayer.php');

//    $majangPlayer1 = new MajangPlayer('123');
//
    //创建房间请求，返回的应该是房间号
    $room = new MaJangRoom('', '1');

    //加入房间请求，发送的应该是玩家号和PlayerID
    $room->joinRoom('1');
    $room->joinRoom('2');
    $room->joinRoom('3');
    $room->joinRoom('4');

    //当有玩家准备的时候使用，返回结果是一个数组，向其它没有准备好的玩家发送消息，如果返回数组为空，游戏自动开始
    //某一局自动开始，需要前台发送一个开始游戏的数据
    $room->playerReady('1');

    //房间自动发牌，此函数会返回当前庄ID（第一次有用),骰子，每个玩家的牌型，提示：这里每个玩家只有13张牌，庄家的第
    //14张牌，需要前台发送一个发牌请求才行
    $result = $room->beginGame();

    

    $room->setPlayerPai('1', array(1, 1, 1, 2, 2, 3, 3));
    $room->setPlayerPai('2', array(1, 1, 2, 2));
    $room->setPlayerPai('3', array(1, 1, 1, 2));
    $room->setPlayerPai('4', array(3, 4, 5, 6));
    //printMaJang($room->getPlayerPai('1'));

    //echo "<br>";

    //这里假设庄家摸牌，也是其他玩家摸牌的结果
   // $r = $room->testMoPai('1', 1);
    //print_r($r);

    //玩家打牌结果，
    $r = $room->testMoPai('4', 1);
    $r = $room->playerDaPai('4', 1);

 //   $r = $room->playerHu('1', 1);
//    $r = $room->playerGuoPai('1');
//    $r = $room->playerGuoPai('2');
//
//    $r = $room->playerPengPai('3', 1);
//    echo $r;
//    printMaJang($room->getPlayerPai('3'));

    
//
//
//    //测试，输出所有玩家的牌
//    for($i = 0; $i < count($result['faPai']); $i++){
//        //print_r($result['faPai'][$i]['pai']);
//        printMaJang($result['faPai'][$i]['pai']);
//        echo "<br>";
//    }

//假设某个玩家打牌，传入数据应该为roomID, playerID,这里省略roomID
//    $r = $room->playerDaPai('1', 12);
//
//   // $tempPai = array(array(1, 4, 4, 8), array(4, 7, 8, 8, 9), array(5, 5, 5, 8));
//    printMaJang(1, $tempPai[0]);
//    printMaJang(2, $tempPai[1]);
//    printMaJang(3, $tempPai[2]);
//    echo "<br>";
//
//    $tempPai = array(array(3,3,4, 7), array(), array());
//    $testPlayer = new MajangPlayer('123');
//    $testPlayer->setPai($tempPai);
//
//    $r = $testPlayer->checkTing(new MajongCard(1, 8));
//
//    $r = $testPlayer->tuiPai(4);
//    print_r($r);

    //print_r($r);

  //  print_r($r);
//    $r = $testPlayer->checkHu(new MajongCard(2, 3));
//    echo $r;

//    //这里假设
//    $majangPlayer = array(new MajangPlayer('123'), new MajangPlayer('456'), new MajangPlayer('789'), new MajangPlayer('135'));
//

//
//    $result = $room->beginGame();
////    print_r($result);
//    for($i = 0; $i < count($majangPlayer); $i++){
//        $majangPlayer[$i]->setPai($result['fapai'][$i]['pai']);
//    }
//
//
//
//
//
//    //打牌测试
//    $pai = $majangPlayer[0]->daPai(array(mt_rand(0, 2), 3));
//
//
//
//
//    print_r($pai);
//    echo "第二个玩家的牌"."<br>";
//    printMaJang(1, $majangPlayer[1]->getPai()[0]);
//    printMaJang(2, $majangPlayer[1]->getPai()[1]);
//    printMaJang(3, $majangPlayer[1]->getPai()[2]);

//    //摸牌测试
//    $pai = $room->moPai();
//    $majangPlayer[0]->moPai($pai);





//
//
//    for($i = 0; $i < count($majangPlayer); $i++){
//        printCards($majangPlayer[$i]->getPai());
//    }


    //printCards($c);

//    $c = $manager->faPai(TONGHUASHUN);
//    $player1 = array('playerID'=>'123', 'cards'=>$manager->faPai());
//    $player2 = array('playerID'=>'124', 'cards'=>$manager->faPai());
//    $player3 = array('playerID'=>'124', 'cards'=>$manager->faPai());
//
//    $c = array(new NiuNiuCard(2, 8, 8), new NiuNiuCard(3, 8, 8), new NiuNiuCard(2, 9, 9), new NiuNiuCard(3, 9, 9), new NiuNiuCard(1, 10, 10));
//
//    $player4 = array('playerID'=>'125', 'cards'=>$c);
//    $n = new NiuniuLogic();

//    printCards($player1['cards']);
//    printCards($player2['cards']);
//    printCards($player3['cards']);
//
//    $roomList = array($player1, $player2, $player3);
//    $roomList = array($player4);
//    echo "<br/>";
//    $r = $n->getNiuniuResult($roomList, true, true);
 //   print_r($r);



    function printCards($cards){
        for($i = 0; $i < count($cards); $i++){
            switch($cards[$i]->type){
                case 1:
                    echo "黑桃".$cards[$i]->num."  ";
                    break;
                case 2:
                    echo "红桃".$cards[$i]->num;
                    break;
                case 3:
                    echo "梅花".$cards[$i]->num;
                    break;
                case 4:
                    echo "方块".$cards[$i]->num;
                    break;
            }
        }
        echo "<br>";
    }

    function printMaJang($majang){

        for($i = 0; $i < count($majang); $i++){
            $type = (int)($majang[$i] / 10 + 1);

            $num = $majang[$i] % 10;
            switch($type){
                case 1:
                    echo $num."筒  ";
                    break;
                case 2:
                    echo $num."条  ";
                    break;
                case 3:
                    echo $num."万  ";
                    break;
            }
        }
    }

?>